package au.com.handsunited.model.relationship;

import org.apache.commons.lang.StringUtils;

/**
 * @author arunda
 *
 */
public enum Role {

	OWNER("Owner"),
	
	ADMINISTRATOR("Administrator"),
	
	MEMBER("Member"),
	
	GUEST("Guest"),
	
	UNKNOWN("");

	
	private final String name;
	
	
	/**
	 * 
	 * @param name
	 */
	private Role(String name) {
		this.name = name;
	}
	
	
	/**
	 * 
	 */
	public String toString() {
		return name;
	}
	
	
	/**
	 * 
	 * @param roleStr
	 * @return
	 */
	public static Role fromString(String roleStr) {
		if (StringUtils.isEmpty(roleStr)) {
			return UNKNOWN;
		} else if (OWNER.name.equalsIgnoreCase(roleStr)){
			return OWNER;
		} else if (ADMINISTRATOR.name.equalsIgnoreCase(roleStr)) {
			return ADMINISTRATOR;
		} else if (MEMBER.name.equalsIgnoreCase(roleStr)){
			return MEMBER;
		} else if (GUEST.name.equalsIgnoreCase(roleStr)) {
			return GUEST;
		} else {
			return UNKNOWN;
		}
	}
	
}
